<?php
/**
 * This file contains the class RegisterEmailView which provides
 * all of the text requirements for the register email page
 *
 * @copyright  2009 A Memory Tree
 * @license    A Memory Tree License
 */
/**
 * This class provides the text for the register email page
 *
 * @copyright  2009 A Memory Tree
 * @license    A Memory Tree License
 */
class RegisterEmailView
{
    /**
     * A place to store pre-prepared messages
     *
     * @var array[string]string
     */
    private $_text;
    /**
      * The html class that provides helpers to display the text
     *
     * @var Html
     */
    private $_html;
    /**
     * Builds the list of text messages
     * 
     * @return void
     * @param Html &$html
     */
    public function __construct(&$html)
    {
        $this->_html = $html;
        $this->_text['emptyEmail'] = 'You have failed to provide an email address.';
        $this->_text['differentEmail'] = 'You have provided two different email addresses.';
        $this->_text['emailSubject'] = 'Request to activate a user account on A Memory Tree';
    }
    /**
     * Return the text that's associated with the given name
     * 
     * @return string
     * @param string $name
     */
    public function text($name)
    {
        return $this->_text[$name];
    }
    /**
     * Provide the previous page message
     *
     * @return string
     * @param mixed $referrer
     */
    function previousPage($referrer)
    {
        $html = $this->_html;
        return 'Please return to the <a href="'.$html->text($referrer).'">previous page</a> and try again.';
    }
    /**
     * Render the error page
     *
     * @return string
     * @param string $errorMessage
     * @param string $previousPage
     */
    function error($errorMessage, $previousPage)
    {
        $html = $this->_html;
        return <<< EOT
<div id="centerbar">
    <h2>Bad email address</h2>
    <p>$errorMessage</p>
    <p>$previousPage</p>
</div>

EOT;
    }
    /**
     * The email message to send
     *
     * @return string
     * @param string $email
     * @param int $userId
     * @param string $authCode
     */
    function emailMessage($email, $userId, $authCode)
    {
        return <<< EOT
    <h2>Email Authentication</h2> 
    <p>A request to use <strong>$email</strong> as an account has been made at <a href="http://amemorytree.co.nz/">amemorytree.co.nz</a></p> 
    <p>If you didn't request this, then we apologise, please delete this email.
    <p>Otherwise, <a href="http://beta.amemorytree.co.nz/resetPassword.php?userid=$userId&amp;auth=$authCode&amp;return=alerts.php">Activate My Account</a></p> 

EOT;
    }
    /**
     * The contents for the page
     *
     * @return string
     * @param string $email
     */
    function content($email)
    {
        $html = $this->_html;
        $email = $html->text($email);
        return <<< EOT
    <h2>Check Your Email</h2>
    <p>An automated email has been sent to <strong>$email</strong></p>
    <p>The email link to <strong>Activate your account</strong> will be valid for the <strong>next two hours</strong>.</p>
    <p>If you do not receive our email shortly, please check your junk and spam mail.</p>

EOT;
    }
    /**
     * The contents for the page
     *
     * @return string
     * @param string $email
     * @param int $userId
     */
    function duplicateUser($email, $userId)
    {
        $html = $this->_html;
        $email = $html->text($email);
        return <<< EOT
    <h2>You're Already Registered</h2>
    <p>The email address <strong>$email</strong> is already registered with us.</p>
    <p>Please login to your account at the <a href="member.php?userid=$userId">Member Page</a>.</p>
    <p>You will also be able to reset your password if you've forgotten it.</p>

EOT;
    }
    /**
     * The contents for the page
     *
     * @return string
     * @param string $email
     */
    function emailFailure()
    {
        return <<< EOT
    <h2>Email Failure</h2>

EOT;
    }
    /**
     * Render the page
     *
     * @return string
     * @param string $content
     */
    function render($content)
    {
        return <<< EOT
<div id="centerbar">
$content
</div>

EOT;
    }
}
?>